package com.moleq.models;

import com.moleq.db.DatabaseSchema;

import android.R.integer;

public class Scale implements IDevModel {
	// CREATE TABLE t_scale_setting
	// (sl_no integer NOT NULL,
	// sl_port integer NOT NULL,
	// sl_device_name varchar(30) NULL,
	// sl_baud varchar(10) NULL,
	// sl_parity varchar(1) NULL,
	// sl_data_bits integer NULL,
	// sl_stop_bits integer NULL,
	// sl_weight_cmd varchar(50) NULL,
	// sl_cancel_cmd varchar(50) NULL,
	// sl_end_char varchar(50) NULL,
	// sl_timeout integer NULL,
	// sl_data_format varchar(10) NULL,
	// sl_divisor integer NULL,
	// sl_using varchar(1) NULL,
	// create_datetime varchar(14) NULL,
	// update_datetime varchar(14) NULL,
	// PRIMARY KEY (sl_no));

	private int no;
	private int port;
	private String deviceName;
	private String baud;
	private String parity;
	private int dataBits;
	private int stopBits;
	private String weightCmd;
	private String cancelCmd;
	private String endChar;
	private int timeout;
	private String dataFormat;
	private int divisor;
	private String using;
	private String create_datetime;
	private String update_datetime;

	public Scale() {
	}

	public Scale(int no, int port, String deviceName, String baud,
			String parity, int dataBits, int stopBits, String weightCmd,
			String cancelCmd, String endChar, int timeout, String dataFormat,
			int divisor, String using) {
		this.no = no;
		this.port = port;
		this.deviceName = deviceName;
		this.baud = baud;
		this.parity = parity;
		this.dataBits = dataBits;
		this.stopBits = stopBits;
		this.weightCmd = weightCmd;
		this.cancelCmd = cancelCmd;
		this.endChar = endChar;
		this.timeout = timeout;
		this.dataFormat = dataFormat;
		this.divisor = divisor;
		this.using = using;
	}

	public Scale(int no, int port, String deviceName, String baud,
			String parity, int dataBits, int stopBits, String weightCmd,
			String cancelCmd, String endChar, int timeout, String dataFormat,
			int divisor, String using, String create_datetime,
			String update_datetime) {
		this.no = no;
		this.port = port;
		this.deviceName = deviceName;
		this.baud = baud;
		this.parity = parity;
		this.dataBits = dataBits;
		this.stopBits = stopBits;
		this.weightCmd = weightCmd;
		this.cancelCmd = cancelCmd;
		this.endChar = endChar;
		this.timeout = timeout;
		this.dataFormat = dataFormat;
		this.divisor = divisor;
		this.using = using;
		this.create_datetime = create_datetime;
		this.update_datetime = update_datetime;
	}

	public int getNo() {
		return no;
	}

	public void setNo(int no) {
		this.no = no;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getDeviceName() {
		return deviceName;
	}

	public void setDeviceName(String deviceName) {
		this.deviceName = deviceName;
	}

	public String getBaud() {
		return baud;
	}

	public void setBaud(String baud) {
		this.baud = baud;
	}

	public String getParity() {
		return parity;
	}

	public void setParity(String parity) {
		this.parity = parity;
	}

	public int getDataBits() {
		return dataBits;
	}

	public void setDataBits(int dataBits) {
		this.dataBits = dataBits;
	}

	public int getStopBits() {
		return stopBits;
	}

	public void setStopBits(int stopBits) {
		this.stopBits = stopBits;
	}

	public String getWeightCmd() {
		return weightCmd;
	}

	public void setWeightCmd(String weightCmd) {
		this.weightCmd = weightCmd;
	}

	public String getCancelCmd() {
		return cancelCmd;
	}

	public void setCancelCmd(String cancelCmd) {
		this.cancelCmd = cancelCmd;
	}

	public String getEndChar() {
		return endChar;
	}

	public void setEndChar(String endChar) {
		this.endChar = endChar;
	}

	public int getTimeout() {
		return timeout;
	}

	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}

	public String getDataFormat() {
		return dataFormat;
	}

	public void setDataFormat(String dataFormat) {
		this.dataFormat = dataFormat;
	}

	public int getDivisor() {
		return divisor;
	}

	public void setDivisor(int divisor) {
		this.divisor = divisor;
	}

	public String getUsing() {
		return using;
	}

	public void setUsing(String using) {
		this.using = using;
	}

	public String getCreate_datetime() {
		return create_datetime;
	}

	public void setCreate_datetime(String create_datetime) {
		this.create_datetime = create_datetime;
	}

	public String getUpdate_datetime() {
		return update_datetime;
	}

	public void setUpdate_datetime(String update_datetime) {
		this.update_datetime = update_datetime;
	}

	@Override
	public boolean isActive() {
		return getUsing().equals("Y");
	}

	@Override
	public String getDevice() {
		// TODO Auto-generated method stub
		return "Scale";
	}

	public String toMGData(String Action) {
		String Result = Action + "|"
				+ DatabaseSchema.ScannerSetting.SCHEMA_NAME + "|(" + getNo()
				+ "," + getPort() + "," + CheckNull(getDeviceName()) + ","
				+ CheckNull(getBaud()) + "," + CheckNull(getParity()) + ","
				+ getDataBits() + "," + getStopBits() + ","
				+ CheckNull(getWeightCmd()) + "," + CheckNull(getCancelCmd())
				+ "," + CheckNull(getEndChar()) + "," + getTimeout() + ","
				+ CheckNull(getDataFormat()) + "," + getDivisor() + ","
				+ CheckNull(getUsing()) + "," + CheckNull(getCreate_datetime())
				+ "," + CheckNull(getUpdate_datetime()) + ")";
		return Result;
	}

	public String CheckNull(String value) {
		if (value == null) {
			return null;
		} else {
			return "'" + value + "'";
		}
	}
}
